package cn.gson.school.service.xitong;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gson.school.dao.xitong.ResourcesDao;
import cn.gson.school.entity.xitong.ResourcesEntity;

@Service
public class ResourceService {
	Logger logger = Logger.getLogger(ResourceService.class);

	@Autowired
	ResourcesDao resourcesDao;
	
	  /**
     * 获取资源树
     *
     * @param status
     * @return
     */
	/* public Iterable<ResourcesEntity> getResourceTree(Boolean status) {
	        Iterable<ResourcesEntity> root;
	        if (status == null) {
	            root = resourcesDao.findByParentIsNull();
	        } else {
	            root = resourcesDao.findByStatusAndParentIsNull(status, resourcesDao.WEIGHT_SORT);
	        }
	        this.buildTree(root, status);
	        return root;
	    }
	 
	 public Iterable<ResourcesEntity> getResourceTree() {
	        return this.getResourceTree(null);
	    }

	    private void buildTree(Iterable<ResourcesEntity> root, Boolean status) {
	        root.forEach(t -> {
	            Iterable<ResourcesEntity> children;

	            if (status == null) {
	                children = resourcesDao.findByParent(t, resourcesDao.WEIGHT_SORT);
	            } else {
	                children = resourcesDao.findByStatusAndParent(status, t, resourcesDao.WEIGHT_SORT);
	            }

	            children.forEach(c -> t.getChildren().add(c));

	            // 此处递归
	            buildTree(children, status);
	        });
	    }*/
}
